<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用 position: absolute 实现垂直居中</title>
    <style>
        /* 父元素样式 */
        .parent {
            position: relative;
            width: 400px;
            height: 400px;
            background-color: #f0f0f0;
        }

        /* 子元素样式 */
        .child {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 100px;
            height: 100px;
            background-color: #3498db;
            color: white;
            text-align: center;
            line-height: 100px;
        }
    </style>
</head>

<body>
    <div class="parent">
        <div class="child">
            垂直居中元素
        </div>
    </div>
</body>

</html>    